﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace dzs.DAL
{
	/// <summary>
	/// 数据访问类:out_storage
	/// </summary>
	public partial class out_storage
	{
		public out_storage()
		{}
        #region  oldMethod

        ///// <summary>
        ///// 得到最大ID
        ///// </summary>
        //public int GetMaxId()
        //{
        //    return DbHelperSQL.GetMaxID("out_storage_id", "out_storage");
        //}

        ///// <summary>
        ///// 是否存在该记录
        ///// </summary>
        //public bool Exists(int out_storage_id)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("select count(1) from out_storage");
        //    strSql.Append(" where out_storage_id=@out_storage_id");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@out_storage_id", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = out_storage_id;

        //    return DbHelperSQL.Exists(strSql.ToString(), parameters);
        //}


        ///// <summary>
        ///// 增加一条数据
        ///// </summary>
        //public int Add(dzs.Model.out_storage model)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("insert into out_storage(");
        //    strSql.Append("material_id,position_id,out_storage_User_id,out_storage_Time,out_storage_count,receive_address,receive_userName,receive_userPhone,out_storageList_id)");
        //    strSql.Append(" values (");
        //    strSql.Append("@material_id,@position_id,@out_storage_User_id,@out_storage_Time,@out_storage_count,@receive_address,@receive_userName,@receive_userPhone,@out_storageList_id)");
        //    strSql.Append(";select @@IDENTITY");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@material_id", SqlDbType.Int,4),
        //            new SqlParameter("@position_id", SqlDbType.Int,4),
        //            new SqlParameter("@out_storage_User_id", SqlDbType.Int,4),
        //            new SqlParameter("@out_storage_Time", SqlDbType.DateTime),
        //            new SqlParameter("@out_storage_count", SqlDbType.Float,8),
        //            new SqlParameter("@receive_address", SqlDbType.VarChar,300),
        //            new SqlParameter("@receive_userName", SqlDbType.NVarChar,30),
        //            new SqlParameter("@receive_userPhone", SqlDbType.VarChar,20),
        //            new SqlParameter("@out_storageList_id", SqlDbType.Int,4)};
        //    parameters[0].Value = model.material_id;
        //    parameters[1].Value = model.position_id;
        //    parameters[2].Value = model.out_storage_User_id;
        //    parameters[3].Value = model.out_storage_Time;
        //    parameters[4].Value = model.out_storage_count;
        //    parameters[5].Value = model.receive_address;
        //    parameters[6].Value = model.receive_userName;
        //    parameters[7].Value = model.receive_userPhone;
        //    parameters[8].Value = model.out_storageList_id;

        //    object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
        //    if (obj == null)
        //    {
        //        return 0;
        //    }
        //    else
        //    {
        //        return Convert.ToInt32(obj);
        //    }
        //}
        ///// <summary>
        ///// 更新一条数据
        ///// </summary>
        //public bool Update(dzs.Model.out_storage model)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("update out_storage set ");
        //    strSql.Append("material_id=@material_id,");
        //    strSql.Append("position_id=@position_id,");
        //    strSql.Append("out_storage_User_id=@out_storage_User_id,");
        //    strSql.Append("out_storage_Time=@out_storage_Time,");
        //    strSql.Append("out_storage_count=@out_storage_count,");
        //    strSql.Append("receive_address=@receive_address,");
        //    strSql.Append("receive_userName=@receive_userName,");
        //    strSql.Append("receive_userPhone=@receive_userPhone,");
        //    strSql.Append("out_storageList_id=@out_storageList_id");
        //    strSql.Append(" where out_storage_id=@out_storage_id");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@material_id", SqlDbType.Int,4),
        //            new SqlParameter("@position_id", SqlDbType.Int,4),
        //            new SqlParameter("@out_storage_User_id", SqlDbType.Int,4),
        //            new SqlParameter("@out_storage_Time", SqlDbType.DateTime),
        //            new SqlParameter("@out_storage_count", SqlDbType.Float,8),
        //            new SqlParameter("@receive_address", SqlDbType.VarChar,300),
        //            new SqlParameter("@receive_userName", SqlDbType.NVarChar,30),
        //            new SqlParameter("@receive_userPhone", SqlDbType.VarChar,20),
        //            new SqlParameter("@out_storageList_id", SqlDbType.Int,4),
        //            new SqlParameter("@out_storage_id", SqlDbType.Int,4)};
        //    parameters[0].Value = model.material_id;
        //    parameters[1].Value = model.position_id;
        //    parameters[2].Value = model.out_storage_User_id;
        //    parameters[3].Value = model.out_storage_Time;
        //    parameters[4].Value = model.out_storage_count;
        //    parameters[5].Value = model.receive_address;
        //    parameters[6].Value = model.receive_userName;
        //    parameters[7].Value = model.receive_userPhone;
        //    parameters[8].Value = model.out_storageList_id;
        //    parameters[9].Value = model.out_storage_id;

        //    int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}

        ///// <summary>
        ///// 删除一条数据
        ///// </summary>
        //public bool Delete(int out_storage_id)
        //{

        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("delete from out_storage ");
        //    strSql.Append(" where out_storage_id=@out_storage_id");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@out_storage_id", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = out_storage_id;

        //    int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}
        ///// <summary>
        ///// 批量删除数据
        ///// </summary>
        //public bool DeleteList(string out_storage_idlist)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("delete from out_storage ");
        //    strSql.Append(" where out_storage_id in (" + out_storage_idlist + ")  ");
        //    int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}


        ///// <summary>
        ///// 得到一个对象实体
        ///// </summary>
        //public dzs.Model.out_storage GetModel(int out_storage_id)
        //{

        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("select  top 1 out_storage_id,material_id,position_id,out_storage_User_id,out_storage_Time,out_storage_count,receive_address,receive_userName,receive_userPhone,out_storageList_id from out_storage ");
        //    strSql.Append(" where out_storage_id=@out_storage_id");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@out_storage_id", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = out_storage_id;

        //    dzs.Model.out_storage model = new dzs.Model.out_storage();
        //    DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
        //    if (ds.Tables[0].Rows.Count > 0)
        //    {
        //        if (ds.Tables[0].Rows[0]["out_storage_id"] != null && ds.Tables[0].Rows[0]["out_storage_id"].ToString() != "")
        //        {
        //            model.out_storage_id = int.Parse(ds.Tables[0].Rows[0]["out_storage_id"].ToString());
        //        }
        //        if (ds.Tables[0].Rows[0]["material_id"] != null && ds.Tables[0].Rows[0]["material_id"].ToString() != "")
        //        {
        //            model.material_id = int.Parse(ds.Tables[0].Rows[0]["material_id"].ToString());
        //        }
        //        if (ds.Tables[0].Rows[0]["position_id"] != null && ds.Tables[0].Rows[0]["position_id"].ToString() != "")
        //        {
        //            model.position_id = int.Parse(ds.Tables[0].Rows[0]["position_id"].ToString());
        //        }
        //        if (ds.Tables[0].Rows[0]["out_storage_User_id"] != null && ds.Tables[0].Rows[0]["out_storage_User_id"].ToString() != "")
        //        {
        //            model.out_storage_User_id = int.Parse(ds.Tables[0].Rows[0]["out_storage_User_id"].ToString());
        //        }
        //        if (ds.Tables[0].Rows[0]["out_storage_Time"] != null && ds.Tables[0].Rows[0]["out_storage_Time"].ToString() != "")
        //        {
        //            model.out_storage_Time = DateTime.Parse(ds.Tables[0].Rows[0]["out_storage_Time"].ToString());
        //        }
        //        if (ds.Tables[0].Rows[0]["out_storage_count"] != null && ds.Tables[0].Rows[0]["out_storage_count"].ToString() != "")
        //        {
        //            model.out_storage_count = decimal.Parse(ds.Tables[0].Rows[0]["out_storage_count"].ToString());
        //        }
        //        if (ds.Tables[0].Rows[0]["receive_address"] != null && ds.Tables[0].Rows[0]["receive_address"].ToString() != "")
        //        {
        //            model.receive_address = ds.Tables[0].Rows[0]["receive_address"].ToString();
        //        }
        //        if (ds.Tables[0].Rows[0]["receive_userName"] != null && ds.Tables[0].Rows[0]["receive_userName"].ToString() != "")
        //        {
        //            model.receive_userName = ds.Tables[0].Rows[0]["receive_userName"].ToString();
        //        }
        //        if (ds.Tables[0].Rows[0]["receive_userPhone"] != null && ds.Tables[0].Rows[0]["receive_userPhone"].ToString() != "")
        //        {
        //            model.receive_userPhone = ds.Tables[0].Rows[0]["receive_userPhone"].ToString();
        //        }
        //        if (ds.Tables[0].Rows[0]["out_storageList_id"] != null && ds.Tables[0].Rows[0]["out_storageList_id"].ToString() != "")
        //        {
        //            model.out_storageList_id = int.Parse(ds.Tables[0].Rows[0]["out_storageList_id"].ToString());
        //        }
        //        return model;
        //    }
        //    else
        //    {
        //        return null;
        //    }
        //}

        ///// <summary>
        ///// 获得数据列表
        ///// </summary>
        //public DataSet GetList(string strWhere)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("select out_storage_id,material_id,position_id,out_storage_User_id,out_storage_Time,out_storage_count,receive_address,receive_userName,receive_userPhone,out_storageList_id ");
        //    strSql.Append(" FROM out_storage ");
        //    if (strWhere.Trim() != "")
        //    {
        //        strSql.Append(" where " + strWhere);
        //    }
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///// <summary>
        ///// 获得前几行数据
        ///// </summary>
        //public DataSet GetList(int Top, string strWhere, string filedOrder)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("select ");
        //    if (Top > 0)
        //    {
        //        strSql.Append(" top " + Top.ToString());
        //    }
        //    strSql.Append(" out_storage_id,material_id,position_id,out_storage_User_id,out_storage_Time,out_storage_count,receive_address,receive_userName,receive_userPhone,out_storageList_id ");
        //    strSql.Append(" FROM out_storage ");
        //    if (strWhere.Trim() != "")
        //    {
        //        strSql.Append(" where " + strWhere);
        //    }
        //    strSql.Append(" order by " + filedOrder);
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///// <summary>
        ///// 获取记录总数
        ///// </summary>
        //public int GetRecordCount(string strWhere)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("select count(1) FROM out_storage ");
        //    if (strWhere.Trim() != "")
        //    {
        //        strSql.Append(" where " + strWhere);
        //    }
        //    object obj = DbHelperSQL.GetSingle(strSql.ToString());
        //    if (obj == null)
        //    {
        //        return 0;
        //    }
        //    else
        //    {
        //        return Convert.ToInt32(obj);
        //    }
        //}
        ///// <summary>
        ///// 分页获取数据列表
        ///// </summary>
        //public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("SELECT * FROM ( ");
        //    strSql.Append(" SELECT ROW_NUMBER() OVER (");
        //    if (!string.IsNullOrEmpty(orderby.Trim()))
        //    {
        //        strSql.Append("order by T." + orderby);
        //    }
        //    else
        //    {
        //        strSql.Append("order by T.out_storage_id desc");
        //    }
        //    strSql.Append(")AS Row, T.*  from out_storage T ");
        //    if (!string.IsNullOrEmpty(strWhere.Trim()))
        //    {
        //        strSql.Append(" WHERE " + strWhere);
        //    }
        //    strSql.Append(" ) TT");
        //    strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///// <summary>
        ///// 得到一个对象实体
        ///// </summary>
        //public dzs.Model.out_storage DataRowToModel(DataRow row)
        //{
        //    dzs.Model.out_storage model = new dzs.Model.out_storage();
        //    if (row != null)
        //    {
        //        if (row["out_storage_id"] != null && row["out_storage_id"].ToString() != "")
        //        {
        //            model.out_storage_id = int.Parse(row["out_storage_id"].ToString());
        //        }
        //        if (row["material_id"] != null && row["material_id"].ToString() != "")
        //        {
        //            model.material_id = int.Parse(row["material_id"].ToString());
        //        }
        //        if (row["position_id"] != null && row["position_id"].ToString() != "")
        //        {
        //            model.position_id = int.Parse(row["position_id"].ToString());
        //        }
        //        if (row["out_storage_User_id"] != null && row["out_storage_User_id"].ToString() != "")
        //        {
        //            model.out_storage_User_id = int.Parse(row["out_storage_User_id"].ToString());
        //        }
        //        if (row["out_storage_Time"] != null && row["out_storage_Time"].ToString() != "")
        //        {
        //            model.out_storage_Time = DateTime.Parse(row["out_storage_Time"].ToString());
        //        }
        //        if (row["out_storage_count"] != null && row["out_storage_count"].ToString() != "")
        //        {
        //            model.out_storage_count = decimal.Parse(row["out_storage_count"].ToString());
        //        }
        //        if (row["receive_address"] != null && row["receive_address"].ToString() != "")
        //        {
        //            model.receive_address = row["receive_address"].ToString();
        //        }
        //        if (row["receive_userName"] != null && row["receive_userName"].ToString() != "")
        //        {
        //            model.receive_userName = row["receive_userName"].ToString();
        //        }
        //        if (row["receive_userPhone"] != null && row["receive_userPhone"].ToString() != "")
        //        {
        //            model.receive_userPhone = row["receive_userPhone"].ToString();
        //        }
        //        if (row["out_storageList_id"] != null && row["out_storageList_id"].ToString() != "")
        //        {
        //            model.out_storageList_id = int.Parse(row["out_storageList_id"].ToString());
        //        }
        //    }
        //    return model;
        //}

        ///*
        ///// <summary>
        ///// 分页获取数据列表
        ///// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@tblName", SqlDbType.VarChar, 255),
        //            new SqlParameter("@fldName", SqlDbType.VarChar, 255),
        //            new SqlParameter("@PageSize", SqlDbType.Int),
        //            new SqlParameter("@PageIndex", SqlDbType.Int),
        //            new SqlParameter("@IsReCount", SqlDbType.Bit),
        //            new SqlParameter("@OrderType", SqlDbType.Bit),
        //            new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
        //            };
        //    parameters[0].Value = "out_storage";
        //    parameters[1].Value = "out_storage_id";
        //    parameters[2].Value = PageSize;
        //    parameters[3].Value = PageIndex;
        //    parameters[4].Value = 0;
        //    parameters[5].Value = 0;
        //    parameters[6].Value = strWhere;	
        //    return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        //}*/

        #endregion  Method

        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("out_storage_id", "out_storage");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int out_storage_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from out_storage");
            strSql.Append(" where out_storage_id=@out_storage_id");
            SqlParameter[] parameters = {
					new SqlParameter("@out_storage_id", SqlDbType.Int,4)
			};
            parameters[0].Value = out_storage_id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(dzs.Model.out_storage model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into out_storage(");
            strSql.Append("material_id,position_id,out_storage_User_id,out_storage_Time,out_storage_count,receive_address,receive_userName,receive_userPhone,out_storageList_id,target_project)");
            strSql.Append(" values (");
            strSql.Append("@material_id,@position_id,@out_storage_User_id,@out_storage_Time,@out_storage_count,@receive_address,@receive_userName,@receive_userPhone,@out_storageList_id,@target_project)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@material_id", SqlDbType.Int,4),
					new SqlParameter("@position_id", SqlDbType.Int,4),
					new SqlParameter("@out_storage_User_id", SqlDbType.Int,4),
					new SqlParameter("@out_storage_Time", SqlDbType.DateTime),
					new SqlParameter("@out_storage_count", SqlDbType.Float,8),
					new SqlParameter("@receive_address", SqlDbType.VarChar,300),
					new SqlParameter("@receive_userName", SqlDbType.NVarChar,30),
					new SqlParameter("@receive_userPhone", SqlDbType.VarChar,20),
					new SqlParameter("@out_storageList_id", SqlDbType.Int,4),
					new SqlParameter("@target_project", SqlDbType.VarChar,50)};
            parameters[0].Value = model.material_id;
            parameters[1].Value = model.position_id;
            parameters[2].Value = model.out_storage_User_id;
            parameters[3].Value = model.out_storage_Time;
            parameters[4].Value = model.out_storage_count;
            parameters[5].Value = model.receive_address;
            parameters[6].Value = model.receive_userName;
            parameters[7].Value = model.receive_userPhone;
            parameters[8].Value = model.out_storageList_id;
            parameters[9].Value = model.target_project;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(dzs.Model.out_storage model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update out_storage set ");
            strSql.Append("material_id=@material_id,");
            strSql.Append("position_id=@position_id,");
            strSql.Append("out_storage_User_id=@out_storage_User_id,");
            strSql.Append("out_storage_Time=@out_storage_Time,");
            strSql.Append("out_storage_count=@out_storage_count,");
            strSql.Append("receive_address=@receive_address,");
            strSql.Append("receive_userName=@receive_userName,");
            strSql.Append("receive_userPhone=@receive_userPhone,");
            strSql.Append("out_storageList_id=@out_storageList_id,");
            strSql.Append("target_project=@target_project");
            strSql.Append(" where out_storage_id=@out_storage_id");
            SqlParameter[] parameters = {
					new SqlParameter("@material_id", SqlDbType.Int,4),
					new SqlParameter("@position_id", SqlDbType.Int,4),
					new SqlParameter("@out_storage_User_id", SqlDbType.Int,4),
					new SqlParameter("@out_storage_Time", SqlDbType.DateTime),
					new SqlParameter("@out_storage_count", SqlDbType.Float,8),
					new SqlParameter("@receive_address", SqlDbType.VarChar,300),
					new SqlParameter("@receive_userName", SqlDbType.NVarChar,30),
					new SqlParameter("@receive_userPhone", SqlDbType.VarChar,20),
					new SqlParameter("@out_storageList_id", SqlDbType.Int,4),
					new SqlParameter("@target_project", SqlDbType.VarChar,50),
					new SqlParameter("@out_storage_id", SqlDbType.Int,4)};
            parameters[0].Value = model.material_id;
            parameters[1].Value = model.position_id;
            parameters[2].Value = model.out_storage_User_id;
            parameters[3].Value = model.out_storage_Time;
            parameters[4].Value = model.out_storage_count;
            parameters[5].Value = model.receive_address;
            parameters[6].Value = model.receive_userName;
            parameters[7].Value = model.receive_userPhone;
            parameters[8].Value = model.out_storageList_id;
            parameters[9].Value = model.target_project;
            parameters[10].Value = model.out_storage_id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int out_storage_id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from out_storage ");
            strSql.Append(" where out_storage_id=@out_storage_id");
            SqlParameter[] parameters = {
					new SqlParameter("@out_storage_id", SqlDbType.Int,4)
			};
            parameters[0].Value = out_storage_id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string out_storage_idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from out_storage ");
            strSql.Append(" where out_storage_id in (" + out_storage_idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public dzs.Model.out_storage GetModel(int out_storage_id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 out_storage_id,material_id,position_id,out_storage_User_id,out_storage_Time,out_storage_count,receive_address,receive_userName,receive_userPhone,out_storageList_id,target_project from out_storage ");
            strSql.Append(" where out_storage_id=@out_storage_id");
            SqlParameter[] parameters = {
					new SqlParameter("@out_storage_id", SqlDbType.Int,4)
			};
            parameters[0].Value = out_storage_id;

            dzs.Model.out_storage model = new dzs.Model.out_storage();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public dzs.Model.out_storage DataRowToModel(DataRow row)
        {
            dzs.Model.out_storage model = new dzs.Model.out_storage();
            if (row != null)
            {
                if (row["out_storage_id"] != null && row["out_storage_id"].ToString() != "")
                {
                    model.out_storage_id = int.Parse(row["out_storage_id"].ToString());
                }
                if (row["material_id"] != null && row["material_id"].ToString() != "")
                {
                    model.material_id = int.Parse(row["material_id"].ToString());
                }
                if (row["position_id"] != null && row["position_id"].ToString() != "")
                {
                    model.position_id = int.Parse(row["position_id"].ToString());
                }
                if (row["out_storage_User_id"] != null && row["out_storage_User_id"].ToString() != "")
                {
                    model.out_storage_User_id = int.Parse(row["out_storage_User_id"].ToString());
                }
                if (row["out_storage_Time"] != null && row["out_storage_Time"].ToString() != "")
                {
                    model.out_storage_Time = DateTime.Parse(row["out_storage_Time"].ToString());
                }
                if (row["out_storage_count"] != null && row["out_storage_count"].ToString() != "")
                {
                    model.out_storage_count = decimal.Parse(row["out_storage_count"].ToString());
                }
                if (row["receive_address"] != null)
                {
                    model.receive_address = row["receive_address"].ToString();
                }
                if (row["receive_userName"] != null)
                {
                    model.receive_userName = row["receive_userName"].ToString();
                }
                if (row["receive_userPhone"] != null)
                {
                    model.receive_userPhone = row["receive_userPhone"].ToString();
                }
                if (row["out_storageList_id"] != null && row["out_storageList_id"].ToString() != "")
                {
                    model.out_storageList_id = int.Parse(row["out_storageList_id"].ToString());
                }
                if (row["target_project"] != null)
                {
                    model.target_project = row["target_project"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select out_storage_id,material_id,position_id,out_storage_User_id,out_storage_Time,out_storage_count,receive_address,receive_userName,receive_userPhone,out_storageList_id,target_project ");
            strSql.Append(" FROM out_storage ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" out_storage_id,material_id,position_id,out_storage_User_id,out_storage_Time,out_storage_count,receive_address,receive_userName,receive_userPhone,out_storageList_id,target_project ");
            strSql.Append(" FROM out_storage ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM out_storage ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.out_storage_id desc");
            }
            strSql.Append(")AS Row, T.*  from out_storage T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "out_storage";
            parameters[1].Value = "out_storage_id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
		
		#region  ExtensionMethod

        /// <summary>
        /// 获取项目累计出库记录
        /// </summary>
        public DataSet GetSumNumsOutStorage(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select sum(out_storage_count) as nums,material_id,material,projectName,proid,unit ");
            strSql.Append(" FROM VporjectOutNums ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" group by material_id,material,projectName,proid,unit ");

        
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取已出库数量(注：此数字包含所有仓管员的出库数量，不分哪个仓管员，只安装物料mid来计算)
        /// </summary>
        /// <param name="mid"></param>
        /// <returns></returns>
        public string GetSumAlreadyOutCount(int mid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select sum(out_storage_count) from out_storage where material_id = "+mid);
            return DbHelperSQL.Query(strSql.ToString()).Tables[0].Rows[0][0].ToString();
        }

        /// <summary>
        /// 获取出库记录
        /// </summary>
        public DataSet GetOutList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM VoutStorage ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

		#endregion  ExtensionMethod
	}
}

